package com.chenjun.core.service.activiti.impl;

import javax.annotation.Resource;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.User;
import org.springframework.stereotype.Service;

import com.chenjun.core.service.activiti.SynUserToActivitiService;
import com.chenjun.core.vo.sys.UserBean;

@Service
public class SynUserToActivitiServiceImpl implements SynUserToActivitiService {

	@Resource
	private IdentityService identityService;
	
	@Override
	public void saveUser(UserBean record) {
		String userID = record.getId();
		User user = identityService.createUserQuery().userId(userID).singleResult();
		if(user == null){
			user = identityService.newUser(userID);
			user.setFirstName(record.getUserName());
			user.setLastName(record.getUserName());
			user.setPassword(record.getPassword());
			identityService.saveUser(user);
		}
	}

	@Override
	public void deleteUser(String userID) {
		identityService.deleteUser(userID);
	}

}
